﻿namespace MSRI.SmsService
{
    using MSRI.HelperClasses;
    using System;
    using System.Runtime.CompilerServices;
    using System.Runtime.Remoting.Messaging;

    public class CallbackSinkClass : MarshalByRefObject
    {
        public event IsClientConnectedDelegate IsClientConnected;

        public event OnDeliveryReportDelegate OnDeliveryReportReceived;

        public event OnMessageReceivedDelegate OnMessageReceived;

        public event OnSmsReceivedDelegate OnSmsReceived;

        public void HandleDeliveryReportReceived(DeliveryReportClass Report)
        {
            if (this.OnDeliveryReportReceived != null)
            {
                this.OnDeliveryReportReceived(Report);
            }
        }

        public bool HandleIsClientConnected()
        {
            return ((this.IsClientConnected != null) && this.IsClientConnected());
        }

        [OneWay]
        public void HandleMessageReceived(string Message)
        {
            if (this.OnMessageReceived != null)
            {
                this.OnMessageReceived(Message);
            }
        }

        public SmsResponseClass HandleSmsReceived(SmsClass Message)
        {
            if (this.OnSmsReceived != null)
            {
                return this.OnSmsReceived(Message);
            }
            return null;
        }
    }
}

